#pragma once

#include <gofcl_spi_stat.h>

// STAT寄存器I2SCH位的取值
typedef enum {
	SPI_STAT_I2SCH_LEFT = 0,
	SPI_STAT_I2SCH_RIGHT = 1,
} spi_stat_i2sch_e;

typedef struct {
	u16_s has_unread : 1;
	u16_s trans_avl : 1;
	__attribute__((packed)) spi_stat_i2sch_e i2s_ch_next : 1;
	u16_s trans_underrun_err : 1;
	u16_s crc_err : 1;
	u16_s cfg_err : 1;
	u16_s recv_overrun_err : 1;
	u16_s in_trans : 1;
	u16_s frame_err : 1;
	u16_s : 7;
} spi_stat_expl_s;

_Static_assert(sizeof(spi_stat_expl_s) == 2,
	       "Struct spi_stat_expl_s defined error!");

static inline spi_stat_expl_s spi_get_stat(spi_qe spi_q) {
	union {
		spi_stat_s s;
		spi_stat_expl_s e;
	} se = {
		.s = spi_rreg_stat_s(spi_q),
	};
	return se.e;
}
